package com.feng.controller.back;

import com.feng.dto.NewsDto;
import com.feng.service.NewsService;
import com.feng.vo.NewsVo;
import com.feng.vo.PageVo;
import com.feng.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 丰
 * @date: 2023/1/1 17:01
 */
@RestController
@RequestMapping("/back/news")
@Api(tags = "后台新闻接口")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @ApiOperation("添加新闻")
    @PutMapping("/add")
    public ResultVo<Integer> add(@RequestBody NewsVo newsVo){
        return newsService.add(newsVo);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/deleteAll")
    public ResultVo<Integer> deleteAll(@RequestBody Integer[] ids){
        return newsService.deleteAll(ids);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/delete/{id}")
    public ResultVo<Integer> delete(@PathVariable("id") Integer id){
        return newsService.deleteById(id);
    }

    @ApiOperation("更新是否可用")
    @PostMapping("/enable")
    public ResultVo<Integer> enable(@RequestBody NewsVo newsVo){
        return newsService.modifyEnable(newsVo);
    }

    @ApiOperation("根据id查找")
    @GetMapping("/findById/{id}")
    public ResultVo<NewsDto> findById(@PathVariable("id") Integer id){
        return newsService.findById(id);
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/getList")
    public ResultVo<List<NewsDto>> getList(PageVo pageVo){
        return newsService.selectAll(pageVo);
    }

    @ApiOperation("更新新闻文章")
    @PostMapping("/updateContent")
    public ResultVo<Integer> updateContent(@RequestBody NewsVo newsVo){
        return newsService.updateContent(newsVo);
    }

    @ApiOperation("更新其他信息")
    @PostMapping("/update")
    public ResultVo<Integer> update(@RequestBody NewsVo newsVo){
        return newsService.update(newsVo);
    }















}
